Mastering Advanced Linux Commands:

 

Complete Guide with Descriptions & Examples

So, you're no longer intimidated by the terminal. You've used ls, cd, and sudo without breaking your system. That’s awesome—but now it’s time to go deeper.

In this post, we'll explore advanced Linux commands, explain what they do, why they matter, and give you real-life examples. Whether you're managing servers, developing software, or automating tasks, these commands will help you work more efficiently and effectively.


🔍 1. grep – Search Text in Files

📘 Description:

grep stands for Global Regular Expression Print. It's used to search for specific text patterns inside files.

🧪 Example:

Search for the word "error" in a log file:

bash

grep "error" /var/log/syslog

Make it case-insensitive:

bash

grep -i "error" /var/log/syslog

Search recursively in all files in a folder:

bash

grep -r "database" /etc/

🧮 2. awk – Advanced Text Processing

📘 Description:

awk is a programming language for working with structured text, especially columns in files.

🧪 Example:

Print the first column of a file:

bash

awk '{print $1}' file.txt

Print the second column only if the third column contains the word "fail":

bash

awk '$3 == "fail" {print $2}' results.txt

🧹 3. sed – Stream Editor

📘 Description:

sed is used for text manipulation, such as find-and-replace, deleting lines, or inserting text.

🧪 Example:

Replace all "apple" with "orange" in a file:

bash

sed 's/apple/orange/g' fruits.txt

Delete all blank lines:

bash

sed '/^$/d' notes.txt

Insert a line after every line containing "Name":

bash

sed '/Name/a\This is a new line' data.txt

🔁 4. xargs – Build and Execute Command Lines

📘 Description:

xargs reads items from input and builds command lines to run on them. Great for pairing with find or grep.

🧪 Example:

Delete all .tmp files:

bash

find . -name "*.tmp" | xargs rm

Run md5sum on all .txt files:

bash

find . -name "*.txt" | xargs md5sum

🕒 5. cron – Schedule Tasks

📘 Description:

cron is used to schedule scripts or commands to run at specific times or intervals.

🧪 Example:

Open your crontab:

bash

crontab -e

Add a job to run a backup every day at 2 AM:

ruby

0 2 * * * /home/user/scripts/backup.sh

Explanation:

  • 0 2 → 2:00 AM

  • * * * → every day, every month, every weekday


🔎 6. find – Search for Files and Directories

📘 Description:

find lets you search for files and folders based on name, type, size, modified time, and more.

🧪 Example:

Find all .log files in /var:

bash

find /var -name "*.log"

Delete all .tmp files:

bash

find . -type f -name "*.tmp" -delete

Find files larger than 100MB:

bash

find / -type f -size +100M

🧰 7. rsync – Sync and Backup Files

📘 Description:

rsync is used to copy files and folders efficiently, syncing only changes between source and destination.

🧪 Example:

Sync a folder to a backup drive:

bash

rsync -avh /home/user/Documents /mnt/backup/

Sync files to a remote server:

bash

rsync -az /var/www user@192.168.1.10:/var/www-backup

Flags used:

  • -a: archive mode

  • -v: verbose

  • -h: human-readable

  • -z: compress files during transfer


⚙️ 8. chmod – Change File Permissions

📘 Description:

chmod changes who can read, write, or execute a file.

🧪 Example:

Give the owner full rights, and others read and execute:

bash

chmod 755 script.sh

Explanation:

  • 7: read (4) + write (2) + execute (1)

  • 5: read (4) + execute (1)

Make a file executable:

bash

chmod +x runme.sh

👤 9. chown – Change File Ownership

📘 Description:

chown changes the user and/or group that owns a file.

🧪 Example:

Make deepak the owner of a file:

bash

chown deepak file.txt

Change owner and group:

bash

chown deepak:developers script.sh

🧪 10. top and htop – Monitor System Processes

📘 Description:

  • top shows live system resource usage (CPU, RAM, running processes).

  • htop is an enhanced, color-coded version (must be installed).

🧪 Example:

Start top:

bash

top

Press q to quit.

Install and run htop:

bash

sudo apt install htop
htop

Press F9 in htop to kill a process directly.


📦 11. tar – Compress and Archive Files

📘 Description:

tar is used to archive multiple files or directories into one .tar, .tar.gz, or .tgz file.

🧪 Example:

Create a compressed archive:

bash

tar -czvf backup.tar.gz /home/user/Documents

Extract it:

bash

tar -xzvf backup.tar.gz

Flags:

  • c: create

  • z: compress with gzip

  • v: verbose (show progress)

  • f: file name


📂 12. Shell Scripting – Automate Like a Pro

📘 Description:

Shell scripts let you automate repetitive tasks by writing commands in a .sh file.

🧪 Example:

bash

#!/bin/bash
echo "Starting backup..."
rsync -avh /home/user/Documents /mnt/backup/
echo "Backup complete."

Save it as backup.sh, then run:

bash

chmod +x backup.sh
./backup.sh

🧙 Bonus Tip: Combine Commands with Pipes and Logic

bash

grep "ERROR" app.log | awk '{print $2}' | sort | uniq -c | sort -nr

What it does:

  • Searches for "ERROR" in app.log

  • Retrieve the second word (could be IP, module, etc.)

  • Sorts and counts unique occurrences

  • Sorts them by frequency

That’s real power—building tools on the fly using simple commands.


🏁 Final Thoughts

Linux is not just an operating system—it’s a toolkit. These advanced commands unlock the full potential of your system and give you the power to automate, optimize, and dominate your workflows.

Start with the examples in this guide, and experiment. The more you use these tools, the more second-nature they become.

Post a Comment

Previous Post Next Post